package com.ewo.controller.ApplicationPageController;

import com.ewo.entity.ApplicationPage.CustomerSettlement;
import com.ewo.entity.ResponseResult;
import com.ewo.service.ApplicationPage.CustomerSettlementService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/settlement")
@CrossOrigin("*")
public class CustomerSettlementController {

    @Resource
    CustomerSettlementService customerSettlementService;

    //根据员工id查找关联已结算工单信息,根据客户id查找客户信息,产品信息
    @GetMapping("/findCSe/{empId}")
    public ResponseResult findCustomerSettlementByEmpId(@PathVariable int empId) {
        List<CustomerSettlement> customerSettlementList = customerSettlementService.findCustomerSettlementByEmpId(empId);
        if (customerSettlementList == null || customerSettlementList.size() == 0) {
            return ResponseResult.fail();
        }
        return ResponseResult.ok(customerSettlementList);
    }

    //根据员工id查找关联已结算工单信息,根据客户id查找客户信息,产品信息,配件信息
    @GetMapping("/findAllCSe/{empId}")
    public ResponseResult findAllCustomerSettlementByEmpId(@PathVariable("empId") int empId){
        List<CustomerSettlement> customerSettlementList = customerSettlementService.findAllCustomerSettlementByEmpId(empId);
        if (customerSettlementList == null || customerSettlementList.size() == 0) {
            return ResponseResult.fail();
        }
        return ResponseResult.ok(customerSettlementList);
    }

    //根据工单id查找当前结算工单信息
    @GetMapping("/findOneCSe/{empId}/{wid}")
    public ResponseResult findOneCustomerSettlementByEmpId(@PathVariable int empId,@PathVariable("wid") int wid){
        CustomerSettlement customerSettlement = customerSettlementService.findOneCustomerSettlementByWid(empId,wid);
        return customerSettlement==null ? ResponseResult.fail():ResponseResult.ok(customerSettlement);
    }

}
